-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build-support: add new hooks #370869
build-support: add new hooks #370869
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/request-for-comments-adding-two-new-hooks/58282/1 |
mutableHomeDirHook
mutableHomeDirHook
tmpdirAsHome
9e45c4c
to
c30ae4a
Compare
c30ae4a
to
1a6ea00
Compare
tmpdirAsHome
1a6ea00
to
48ddab5
Compare
48ddab5
to
2246ddf
Compare
2246ddf
to
e45fb8f
Compare
Will this hook also be avaliable in preConfig or some thing like this? Here is some example: nixpkgs/pkgs/by-name/af/affine/package.nix Line 109 in 1a685a9
nixpkgs/pkgs/by-name/af/affine/package.nix Line 156 in 1a685a9
|
It can actually be added to any phase hooks, so yeah. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the Idea overall.
I also have two feedback Points:
- This could be two PRs.
- For my taste the amount of documentation is not enough. Especially i wouldn like to know stuff that happens internally, like what value is. $HOME set to and when?
While I'm all for splitting PR, make sure that they have a clear scope, I really don't understand why I would need to split this one. The scope is clear, even the commits are correctly split. So I'm sorry but no, I won't split this PR in two.
OK I will improve it. |
e45fb8f
to
e8e0a8d
Compare
4823191
to
881d72c
Compare
Planning to merge this tomorrow morning, feel free to raise your voice if you believe it is a bad idea. |
I'd like to see some examples of packages helped by these hooks, at the very least. |
Here's some Github search where it would be used:
|
doc/stdenv/stdenv.chapter.md
Outdated
@@ -1375,6 +1375,26 @@ This hook only runs when compiling for Linux. | |||
|
|||
This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file. | |||
|
|||
### `add-bin-to-path.sh` {#add-bin-to-path.sh} | |||
|
|||
This setup hook adds the `./bin/` directory to the `PATH` environment variable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably at least explicitly mention it's adding $out/bin
and not $sourceRoot/bin
or whatever. Honestly, this is my big concern with this hook: it's not immediately obvious what exactly it does, and the thing it does comes with a bunch of weird caveats (what if there are multiple outputs? what if the binaries are in sbin? etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I just updated the documentation. Let me know if this resolves this feedback.
881d72c
to
f811073
Compare
|
||
addBinToPath () { | ||
# shellcheck disable=SC2154 | ||
if [ -d "$out/bin" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we log something if the directory doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been changed since then: https://github.com/NixOS/nixpkgs/pull/378110/files#diff-d390481be231cb8f7d3eaf4cbc0cd6580b5e469d9c3ac6c5a91a8c9fa62f3799
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It hasn't been suggested during the month this PR has been opened, so no.
That said, while implementing that hook this morning, I had an issue because of that if condition. I removed it in 62d4ca6
|
||
export HOME | ||
|
||
writableTmpDirAsHome () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we name the hook "writable" shouldn't it also call chmod +w or so to make sure it is writable? Right now with the wrong umask it isn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't needed so far, but it could be done in a future PR.
|
||
writableTmpDirAsHome () { | ||
if [ ! -w "$HOME" ]; then | ||
HOME="$NIX_BUILD_TOP/.home" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that a hidden directory and not just home?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been suggested to name it as such, I don't really have any preference.
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-24.11
git worktree add -d .worktree/backport-370869-to-release-24.11 origin/release-24.11
cd .worktree/backport-370869-to-release-24.11
git switch --create backport-370869-to-release-24.11
git cherry-pick -x 87521c59b636ae9073c58bd549b4cdc334a3dc28 f8110737aeedf8ba92ea46a0b1d2d298843d7c06 |
|
||
writableTmpDirAsHome () { | ||
if [ ! -w "$HOME" ]; then | ||
HOME="$NIX_BUILD_TOP/.home" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry that this will break when run under nix-shell. Can we use something other than $NIX_BUILD_TOP please? (Or define a new env var for where the build actually happens, which is also valid in nix-shell?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, break nix-shell and use of the keepBuildTree
setup hook, as per the linked issue above.
Hello everyone,
During the holidays, I spent some time packaging Python packages and noticed that some of them require a valid and mutable home directory to build or function properly.
Currently, the default behavior of the Nix stdenv is to set the
HOME
environment variable to/homeless-shelter
, a read-only directory. While this approach is consistent, it can cause issues for packages that expect a writable home directory.After performing a treewide search in
nixpkgs
, I found approximately 500 instances whereexport HOME
is used (rg -c "export HOME" | wc -l
) and 300 whereexport PATH
is used (rg -c "export PATH" | wc -l
). These repetitive patterns inspired me to propose a solution adhering to the DRY principle.I created custom hooks,
tmpdirAsHomeHook
, which sets up a mutable home directory automatically when added tonativeBuildInputs
or another appropriate place. Additionally,addBinToPath
, which modifies thePATH
environment variable to includebin/
if available.I’d appreciate your feedback on this approach and have a few questions:
nixpkgs
?tmpdirAsHomeHook
tomutableHomeDirHook
for better clarity. What do you think?addEnvHooks "$targetOffset" addBinToPath
. I’m not entirely confident about the best way to implement this. Could you provide some guidance?Thanks for taking the time to review this. I look forward to hearing your thoughts and suggestions!
Best regards
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.